package com.leyou.sort.controller;

import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leyou.mall.data.entity.Result;
import com.leyou.sort.entity.MallSort;
import com.leyou.sort.service.IMallSortServiceMhr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 车矣捕
 * @version 1.0
 * @description: 描述
 * @date 2022/7/14 20:28
 */
@RestController
@RequestMapping("/mallSort")
public class MallSortControllerMhr {
    @Autowired
    IMallSortServiceMhr mallSortService;


    @PostMapping("/sortList")
    public Result sortList(MallSort vo){
        QueryWrapper<MallSort> queryWrapper = new QueryWrapper<>();
        long pageNum=vo.getPageNum();
        long pageSize= vo.getPageSize();
        queryWrapper.orderByDesc("id");
        return Result.success(mallSortService.page(new Page<>(pageNum, pageSize),queryWrapper));
    }

    /*** @description:  上/下 架 */
    @PostMapping("/updateStatus")
    public Result updateStatus(MallSort vo) {
        System.out.println("上/下 架:--"+vo);
        return Result.success(mallSortService.updateById(vo));
    }


    /*** @description:  添加 */
    @RequestMapping("/addSort")
    public Result addSort(MallSort vo) {

        vo.setNumber(Integer.parseInt(RandomUtil.randomNumbers(6)));
        System.err.println(vo.toString());
        return Result.success(mallSortService.saveMallSort(vo));
    }

    @RequestMapping("/deleteSort/{id}")
    public Result deleteSort(@PathVariable Integer id) {

        System.err.println(id);
        return Result.success(mallSortService.removeById(id));
    }
}
